package com.lovepick.fragment;

import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.TimePicker;

import com.baidu.mapapi.MKAddrInfo;
import com.baidu.mapapi.MKDrivingRouteResult;
import com.lovepick.GlobalApp;
import com.lovepick.PoiDialogActivity;
import com.lovepick.R;
import com.lovepick.adapter.MyOrderAdapter;
import com.lovepick.bean.Order;
import com.lovepick.http.HttpThread;
import com.lovepick.map.MapHelper;
import com.lovepick.util.BaseUtils;
import com.lovepick.util.Constant;
import com.lovepick.util.IRecmdListener;
import com.lovepick.util.NumberPickerDialog;

public class OrderFragment extends Fragment implements View.OnClickListener
{
	private static final String TAG = "OrderFragment";
	private static boolean isRelease = false;
	private static final String RESTORE_PREFS = "order_restore";
	private static final int REQUEST_CODE_SRC = 0;
	private static final int REQUEST_CODE_DEST = 1;

	private EditText mSrcEdt;
	private EditText mDestEdt;
	private EditText mTimeEdt;
	private EditText mDateEdt;
	private EditText mOffsetEdt;
	private EditText mMoneyEdt;
	private EditText mCountEdt;

	private TextView mCountText;

	private ImageButton mLocationBtn;
	private RadioGroup mRoleRadioGroup;

	private ProgressBar mSrcBar;
	private ProgressBar mReleaseBar;

	private String src, dest, date, time, goTime;
	private int offset = Order.OFFSET_DEFAULT;
	private int money = Order.MONEY_DEFAULT;
	private int count = Order.COUNT_DEFAULT_PASSENGER;
	private double slat, slng, dlat, dlng;
	private String role = Constant.PASSENGER;

	private OrderHandler mHandler = null;
	private MapHelper mMapHelper = null;
	private HttpThread mThread = null;

	private List<Order> mOrders = null;
	private MyOrderAdapter mAdapter = null;
	private IRecmdListener mListener;

	@Override
	public void onAttach(Activity activity)
	{
		super.onAttach(activity);

		// 确保包含了本Fragment的Activity实现了相关回调接口, 否则抛出异常.
		try
		{
			mListener = (IRecmdListener) activity;
		}
		catch (ClassCastException e)
		{
			throw new ClassCastException(activity.toString()
					+ " must implement IRecmdListener");
		}
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState)
	{
		Log.i(TAG, "---onActivityCreated---");
		super.onActivityCreated(savedInstanceState);
		setHasOptionsMenu(true);
		mHandler = new OrderHandler(this);
		GlobalApp.getInstance().getMapManager().start();
		mMapHelper = new MapHelper(GlobalApp.getInstance().getMapManager(), mHandler);
		findView();
		setListeners();
		restore();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState)
	{
		Log.i(TAG, "---onCreateView---");
		View view = inflater.inflate(R.layout.order_release, container, false);
		return view;
	}

	@Override
	public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
	{
		inflater.inflate(R.menu.order_release, menu);

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		switch (item.getItemId())
		{
			case R.id.menu_history:
				Log.i(TAG, "发布历史");
				getHistoryOrders();
				return true;

			case R.id.menu_release:
				Log.i(TAG, "发布路线");
				releaseOrder();
				return true;

			case R.id.menu_reset:
				Log.i(TAG, "重置数据");
				resetInfos();
				return true;

			default:
				break;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v)
	{
		// TODO Auto-generated method stub

		switch (v.getId())
		{
			case R.id.edt_src:
				Intent srcIntent = new Intent(getActivity(), PoiDialogActivity.class);
				srcIntent.putExtra(Order.POINT_TYPE, Order.SRC);
				startActivityForResult(srcIntent, REQUEST_CODE_SRC);
				break;

			case R.id.edt_dest:
				Intent destIntent = new Intent(getActivity(), PoiDialogActivity.class);
				destIntent.putExtra(Order.POINT_TYPE, Order.DEST);
				startActivityForResult(destIntent, REQUEST_CODE_DEST);
				break;
				// 出发日期
			case R.id.edt_date:
				showDatePickerDialog();
				break;

				// 出发时刻
			case R.id.edt_time:
				showTimePickerDialog();
				break;

				// 浮动时间
			case R.id.edt_offset:
				showOffsetDialog();
				break;

				// 单座出价
			case R.id.edt_money:
				showMoneyDialog();
				break;

				// 座位数量
			case R.id.edt_count:
				showCountDialog();
				break;

				// 定位
			case R.id.btn_location:
				getCurrentLoc();
				break;

			default:
				break;
		}
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		super.onActivityResult(requestCode, resultCode, data);
		if (data != null && resultCode == Activity.RESULT_OK)
		{
			Log.i(TAG, "## get poi result intent ##");
			Log.i(TAG, data.toString());
			String addr = data.getStringExtra(Order.ADDR_NAME);
			double lat = data.getDoubleExtra(Order.LAT, 0);
			double lng = data.getDoubleExtra(Order.LNG, 0);
			switch (requestCode)
			{
				case REQUEST_CODE_SRC:
					src = addr;
					slat = lat;
					slng = lng;
					mSrcEdt.setText(src);
					break;

				case REQUEST_CODE_DEST:
					dest = addr;
					dlat = lat;
					dlng = lng;
					mDestEdt.setText(dest);
					//GeoPoint start = new GeoPoint((int) (slat*1E6), (int) (slng*1E6));
					//GeoPoint end = new GeoPoint((int) (dlat*1E6), (int) (dlng*1E6));
					//mMapHelper.searchDrivingRoute(start, end);
					break;

				default:
					break;
			}
		}
	}

	private void findView()
	{
		mSrcEdt = (EditText) getActivity().findViewById(R.id.edt_src);
		mDestEdt = (EditText) getActivity().findViewById(R.id.edt_dest);
		mDateEdt = (EditText) getActivity().findViewById(R.id.edt_date);
		mTimeEdt = (EditText) getActivity().findViewById(R.id.edt_time);
		mOffsetEdt = (EditText) getActivity().findViewById(R.id.edt_offset);
		mMoneyEdt = (EditText) getActivity().findViewById(R.id.edt_money);
		mCountEdt = (EditText) getActivity().findViewById(R.id.edt_count);
		mCountText = (TextView) getActivity().findViewById(R.id.txv_count);
		mSrcBar = (ProgressBar) getActivity().findViewById(R.id.progBar_src);
		mReleaseBar = (ProgressBar) getActivity().findViewById(R.id.progBar_release);
		mLocationBtn = (ImageButton) getActivity().findViewById(R.id.btn_location);
		mRoleRadioGroup = (RadioGroup) getActivity().findViewById(R.id.radioGroup_role);
	}

	private void setListeners()
	{

		mRoleRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener()
		{

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId)
			{
				// TODO Auto-generated method stub
				//Log.i(TAG, "##checkedChanged##");
				switch (checkedId)
				{
					case R.id.radio_driver:
						//Log.i(TAG, "##driver checked##");
						count = Order.COUNT_DEFAULT_DRIVER;
						mCountText.setText(R.string.count_driver);
						mCountEdt.setText(String.valueOf(Order.COUNT_DEFAULT_DRIVER));
						role = Constant.DRIVER;
						break;

					case R.id.radio_passenger:
						//Log.i(TAG, "##passenger checked##");
						count = Order.COUNT_DEFAULT_PASSENGER;
						mCountText.setText(R.string.count_passenger);
						mCountEdt.setText(String.valueOf(Order.COUNT_DEFAULT_PASSENGER));
						role = Constant.PASSENGER;
						break;

					default:
						mCountText.setText(R.string.count_driver);
						mCountEdt.setText(String.valueOf(Order.COUNT_DEFAULT_DRIVER));
						role = Constant.DRIVER;
						break;
				}
			}
		});

		mSrcEdt.setOnClickListener(this);
		mDestEdt.setOnClickListener(this);
		mLocationBtn.setOnClickListener(this);
		mDateEdt.setOnClickListener(this);
		mTimeEdt.setOnClickListener(this);
		mOffsetEdt.setOnClickListener(this);
		mCountEdt.setOnClickListener(this);
		mMoneyEdt.setOnClickListener(this);
	}

	private void init()
	{
		Log.i(TAG, "---init---");
		mRoleRadioGroup.check(R.id.radio_passenger);
		Calendar calendar = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		date = sdf.format(calendar.getTime());
		mDateEdt.setText(date);
		sdf.applyPattern("HH:mm:ss");
		time = sdf.format(calendar.getTime());
		mTimeEdt.setText(time);
		offset = Order.OFFSET_DEFAULT;
		money = Order.MONEY_DEFAULT;
		count = Order.COUNT_DEFAULT_PASSENGER;
		mOffsetEdt.setText(String.valueOf(offset));
		mCountEdt.setText(String.valueOf(count));
		mMoneyEdt.setText(String.valueOf(money));
	}

	private void resetInfos()
	{
		mSrcEdt.setText(R.string.empty);
		mDestEdt.setText(R.string.empty);
		mCountEdt.setText(R.string.empty);
		mDateEdt.setText(R.string.empty);
		mTimeEdt.setText(R.string.empty);
		mOffsetEdt.setText(R.string.empty);
		mMoneyEdt.setText(R.string.empty);
		src = dest = goTime = date = time = "";
		count = Order.COUNT_DEFAULT_PASSENGER;
		offset = Order.OFFSET_DEFAULT;
		money = Order.MONEY_DEFAULT;
	}

	private void getCurrentLoc()
	{
		Log.i(TAG, "-----getCurrentLoc-----");
		if (BaseUtils.getNetworkState())
		{
			mSrcEdt.setText(R.string.get_current_loc);
			mSrcEdt.setFocusable(false);
			mSrcBar.setVisibility(View.VISIBLE);
			mMapHelper.getCurrentLocation();
		}
		else
		{
			BaseUtils.showToast(getActivity(), R.string.network_error);
		}
	}

	private String getOrderEcodeUrl()
	{
		String encodeUrl = null;

		goTime = date + " " + time;
		if (checkOrderInfo())
		{
			String tmp = "";
			tmp += ("?test=test");
			tmp += ("&src=" + src);
			tmp += ("&slat=" + slat);
			tmp += ("&slng=" + slng);
			tmp += ("&dest=" + dest);
			tmp += ("&dlat=" + dlat);
			tmp += ("&dlng=" + dlng);
			tmp += ("&goTime=" + goTime);
			tmp += ("&offset=" + offset);
			tmp += ("&money=" + money);
			tmp += ("&count=" + count);
			tmp += ("&role=" + role);
			try
			{
				Log.i(TAG, tmp);
				encodeUrl = java.net.URLEncoder.encode(tmp, "UTF-8");

			}
			catch (UnsupportedEncodingException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
				encodeUrl = null;
			}
		}
		return encodeUrl;
	}

	private boolean checkOrderInfo()
	{
		if (BaseUtils.isEmptyString(src))
		{
			BaseUtils.showToast(getActivity(), "请输入起点!");
			return false;
		}
		if (BaseUtils.isEmptyString(dest))
		{
			BaseUtils.showToast(getActivity(), "请输入终点!");
			return false;
		}
		if (BaseUtils.isEmptyString(goTime))
		{
			BaseUtils.showToast(getActivity(), "请选择日期和时刻!");
			return false;
		}

		return true;
	}

	private void releaseOrder()
	{
		isRelease = true;
		if (BaseUtils.getNetworkState())
		{
			String encodeUrl = getOrderEcodeUrl();
			if (encodeUrl != null)
			{
				final String url = Constant.HTTP_URL_ORDER_RELEASE + encodeUrl;
				mThread = new HttpThread(mHandler, Constant.HTTP_METHOD_GET, url, null);
				mThread.start();
				mReleaseBar.setVisibility(View.VISIBLE);
			}
		}
		else
		{
			BaseUtils.showToast(getActivity(), R.string.network_error);
		}

	}

	private void showDatePickerDialog()
	{
		DatePickerDialog.OnDateSetListener callBack = new DatePickerDialog.OnDateSetListener()
		{

			@Override
			public void onDateSet(DatePicker view, int year, int monthOfYear,
					int dayOfMonth)
			{
				// TODO Auto-generated method stub
				final Calendar calendar = Calendar.getInstance();
				calendar.set(view.getYear(), view.getMonth(), view.getDayOfMonth());
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				date = sdf.format(calendar.getTime());
				mDateEdt.setText(date);
			}
		};

		final Calendar c = Calendar.getInstance();
		int year = c.get(Calendar.YEAR);
		int month = c.get(Calendar.MONTH);
		int day = c.get(Calendar.DAY_OF_MONTH);

		DatePickerDialog dialog = new DatePickerDialog(getActivity(),
				callBack, year, month, day);
		dialog.setTitle(R.string.dialog_title_startdate);
		dialog.show();
	}

	private void showTimePickerDialog()
	{
		TimePickerDialog.OnTimeSetListener callBack = new TimePickerDialog.OnTimeSetListener()
		{

			@Override
			public void onTimeSet(TimePicker view, int hourOfDay, int minute)
			{
				// TODO Auto-generated method stub
				Calendar calendar = Calendar.getInstance();
				calendar.set(Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH,
						view.getCurrentHour(), view.getCurrentMinute());
				SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
				time = sdf.format(calendar.getTime());
				mTimeEdt.setText(time);
			}
		};

		Calendar c = Calendar.getInstance();
		int hour = c.get(Calendar.HOUR_OF_DAY);
		int minute = c.get(Calendar.MINUTE);

		TimePickerDialog dialog = new TimePickerDialog(getActivity(),
				callBack, hour, minute, true);
		dialog.setTitle(R.string.dialog_title_starttime);
		dialog.show();
	}

	private void showOffsetDialog()
	{
		NumberPickerDialog.OnNumberSetListener callBack = new NumberPickerDialog.OnNumberSetListener()
		{

			@Override
			public void onNumberSet(int number)
			{
				// TODO Auto-generated method stub
				offset = number;
				mOffsetEdt.setText(String.valueOf(offset));
			}
		};

		NumberPickerDialog dialog = new NumberPickerDialog(getActivity(),
				callBack,
				Order.OFFSET_DEFAULT,
				Order.OFFSET_MIN,
				Order.OFFSET_MAX,
				R.string.numberpick_offset,
				R.string.offset_min);
		dialog.show();
	}

	private void showMoneyDialog()
	{
		NumberPickerDialog.OnNumberSetListener callBack = new NumberPickerDialog.OnNumberSetListener()
		{

			@Override
			public void onNumberSet(int number)
			{
				// TODO Auto-generated method stub
				money = number;
				mMoneyEdt.setText(String.valueOf(money));
			}
		};

		NumberPickerDialog dialog = new NumberPickerDialog(
				getActivity(),
				callBack,
				Order.MONEY_DEFAULT,
				Order.MONEY_MIN,
				Order.MONEY_MAX,
				R.string.numberpick_money,
				R.string.money_unit);
		dialog.show();
	}

	private void showCountDialog()
	{
		NumberPickerDialog.OnNumberSetListener callBack = new NumberPickerDialog.OnNumberSetListener()
		{

			@Override
			public void onNumberSet(int number)
			{
				// TODO Auto-generated method stub
				count = number;
				mCountEdt.setText(String.valueOf(count));

			}
		};

		int title = (Constant.DRIVER.equals(role) ?
				R.string.numberpick_count_driver : R.string.numberpick_count_passenger);
		int number = (Constant.DRIVER.equals(role) ? Order.COUNT_DEFAULT_DRIVER : Order.COUNT_DEFAULT_PASSENGER);

		NumberPickerDialog dialog = new NumberPickerDialog(getActivity(),
				callBack,
				number,
				Order.COUNT_MIN,
				Order.COUNT_MAX,
				title,
				R.string.count_unit);
		dialog.show();
	}

	private void getHistoryOrders()
	{
		isRelease = false;
		String url = Constant.HTTP_URL_ORDER_HISTORY + "/" + role;
		mThread = new HttpThread(mHandler, Constant.HTTP_METHOD_GET, url, null);
		mThread.start();
		mReleaseBar.setVisibility(View.VISIBLE);
	}

	private void restore()
	{
		Log.i(TAG, "---restore---");

		SharedPreferences sp = getActivity().getSharedPreferences(RESTORE_PREFS, Context.MODE_PRIVATE);

		if (sp.contains(Order.SRC) && sp.contains(Order.DEST))
		{
			src = sp.getString(Order.SRC, "");
			mSrcEdt.setText(src);
			dest = sp.getString(Order.DEST, "");
			mDestEdt.setText(dest);
			goTime = sp.getString(Order.GOTIME, "");

			date = sp.getString(Order.DATE, "");
			time = sp.getString(Order.TIME, "");
			offset = sp.getInt(Order.OFFSET, Order.OFFSET_DEFAULT);
			mOffsetEdt.setText(String.valueOf(offset));
			count = sp.getInt(Order.COUNT, Order.COUNT_DEFAULT_PASSENGER);
			mCountEdt.setText(String.valueOf(count));
			money = sp.getInt(Order.MONEY, Order.MONEY_DEFAULT);
			mMoneyEdt.setText(String.valueOf(money));
			slat = Double.parseDouble(sp.getString(Order.SLAT, "0.0"));
			slng = Double.parseDouble(sp.getString(Order.SLNG, "0.0"));
			dlat = Double.parseDouble(sp.getString(Order.DLAT, "0.0"));
			dlng = Double.parseDouble(sp.getString(Order.DLNG, "0.0"));
			mRoleRadioGroup.check(sp.getInt(Order.ROLE,
					R.id.radio_passenger));

		}
		else
		{
			Log.i(TAG, "##no preferences##");
			init();
		}
	}

	@Override
	public void onPause()
	{
		Log.i(TAG, "---onPause---");
		SharedPreferences sp = getActivity().getSharedPreferences(RESTORE_PREFS, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = sp.edit();
		goTime = date + " " + time;
		editor.putString(Order.SRC, src);
		editor.putString(Order.DEST, dest);
		editor.putString(Order.DATE, date);
		editor.putString(Order.TIME, time);
		editor.putString(Order.GOTIME, goTime);
		editor.putInt(Order.OFFSET, offset);
		editor.putInt(Order.COUNT, count);
		editor.putInt(Order.MONEY, money);
		editor.putString(Order.SLAT, String.valueOf(slat));
		editor.putString(Order.SLNG, String.valueOf(slng));
		editor.putString(Order.DLAT, String.valueOf(dlat));
		editor.putString(Order.DLNG, String.valueOf(dlng));
		int id = mRoleRadioGroup.getCheckedRadioButtonId();
		if (R.id.radio_driver == id)
		{
			role = Constant.DRIVER;
		}
		else if (R.id.radio_passenger == id)
		{
			role = Constant.PASSENGER;
		}
		editor.putInt(Order.ROLE, id);
		editor.commit();
		super.onPause();
	}


	private static class OrderHandler extends Handler
	{
		private WeakReference<OrderFragment> mReference;
		private OrderFragment mFragment;

		public OrderHandler(OrderFragment fragment)
		{
			mReference = new WeakReference<OrderFragment>(fragment);
		}

		@Override
		public void handleMessage(Message msg)
		{
			mFragment = mReference.get();
			switch (msg.what)
			{
				case MapHelper.ADDR_COMPLETE:
					Log.i(TAG, "##getAddrInfo##");
					MKAddrInfo addrInfo = mFragment.mMapHelper.getAddrInfo();
					if (addrInfo != null)
					{
						mFragment.src = addrInfo.strAddr;
						mFragment.mSrcEdt.setText(mFragment.src);
						mFragment.slat = (addrInfo.geoPt.getLatitudeE6()) / 1E6;
						mFragment.slng = (addrInfo.geoPt.getLongitudeE6()) / 1E6;
					}
					else
					{
						BaseUtils.showToast(mFragment.getActivity(), R.string.get_current_loc_fail);
					}

					mFragment.mSrcBar.setVisibility(View.GONE);
					mFragment.mSrcEdt.setFocusableInTouchMode(true);
					break;

				case MapHelper.DRIVE_COMPLETE:
					MKDrivingRouteResult drivingRouteResult = mFragment.mMapHelper.getDrivingRouteResult();
					if (null == drivingRouteResult)
					{

					}
					else
					{

						//ArrayList<GeoPoint> points = drivingRouteResult.getPlan(0).getRoute(0).getArrayPoints();
					}
					break;

				case Constant.MSG_HTTP_SUCCESS:
					mFragment.mReleaseBar.setVisibility(View.GONE);
					String result = msg.getData().getString(Constant.HTTP_RESULT);
					result = result.replace("\\\"", "\"")					// \" --> "
							.replace("\"[", "[")							// "[ --> [
							.replace("]\"", "]")							// ]" --> ]
							.replace("\"points\":\"\"", "\"points\":[]");	// "points":"" --> "points":[]
					Log.i(TAG, result);
					if (result.startsWith(Constant.JSON_ARRAY_START))
					{
						if (isRelease)
						{
							Log.i(TAG, "##release success##");
							BaseUtils.showToast(mFragment.getActivity(), R.string.order_release_success);
							//mFragment.mCallBack.onReleaseSuccess(result);
							mFragment.mListener.onGetRecmd(mFragment.role, true, result);
						}
						else
						{
							Log.i(TAG, "##获取到历史数据##");
							mFragment.mOrders = BaseUtils.getOrders(result, false);
							if (null == mFragment.mOrders)
							{
								BaseUtils.showToast(mFragment.getActivity(), R.string.no_history);
							}
							else
							{
								mFragment.mAdapter = new MyOrderAdapter(mFragment.getActivity(), mFragment.mOrders);
								AlertDialog.Builder builder = new AlertDialog.Builder(mFragment.getActivity());
								builder.setTitle(R.string.dialog_title_history);
								builder.setAdapter(mFragment.mAdapter, new DialogInterface.OnClickListener()
								{

									@Override
									public void onClick(DialogInterface dialog, int which)
									{
										// TODO Auto-generated method stub

										Order order = mFragment.mOrders.get(which);
										mFragment.src = order.getSrc();
										mFragment.mSrcEdt.setText(order.getSrc());
										mFragment.dest = order.getDest();
										mFragment.mDestEdt.setText(order.getDest());
										mFragment.goTime = order.getGoTime();
										String[] s = order.getGoTime().split(" ");
										mFragment.date = s[0];
										mFragment.mDateEdt.setText(mFragment.date);
										mFragment.time = s[1];
										mFragment.mTimeEdt.setText(mFragment.time);
										mFragment.count = order.getCount();
										mFragment.mCountEdt.setText(String.valueOf(mFragment.count));
										mFragment.offset = order.getOffset();
										mFragment.mOffsetEdt.setText(String.valueOf(mFragment.offset));
										mFragment.money = order.getMoney();
										mFragment.mMoneyEdt.setText(String.valueOf(mFragment.money));
										mFragment.slat = order.getSlat();
										mFragment.slng = order.getSlng();
										mFragment.dlat = order.getDlat();
										mFragment.dlng = order.getDlng();
									}
								});
								builder.create().show();
							}
						}

					}
					else
					{
						if (isRelease)
						{
							BaseUtils.showToast(mFragment.getActivity(), R.string.order_release_fail);
						}
						else
						{
							BaseUtils.showToast(mFragment.getActivity(), R.string.no_history);
						}
					}
					break;

				case Constant.MSG_HTTP_ERROR:
					mFragment.mReleaseBar.setVisibility(View.GONE);
					BaseUtils.showToast(mFragment.getActivity(), R.string.network_error);
					break;

				default:
					mFragment.mReleaseBar.setVisibility(View.GONE);
					BaseUtils.showToast(mFragment.getActivity(), R.string.network_error);
					break;
			}
		}
	}
}
